var util = require('../../../../utils/util.js')
var _this
const shareText = '我在这里找到了11个志趣相同的人其中7个小哥哥,4个小姐姐。快来试一试，让我们愉快的玩耍吧'
const app = getApp()
Page({
    data: {
      sex:1,  //0未知 1男 2女
      manSelected:'btnNormal',
      womenSelected:'btnNormal',
      action: 'none',     //共享图片组件动作 none初始动作 create为产生图片  save为保存图片
      fillContent: shareText,     //共享图片里要填充的文字，为了示例默认用了上面常量shareText
      imagePath: '',
      cutsomTag: ''
    },
    sexFinishedHandle: function(e) {
      console.log(e.detail)
      app.userSetting.sex = e.detail.action
      console.log(app.userSetting.sex)
    },
  birthdayFinishedHandle: function(e) {
    console.log(e.detail)
    if (e.detail.action == 0) {
      //返回上一题
    }else{
      app.userSetting.birthday = e.detail.birthday
      console.log(app.userSetting.birthday)
    }
  },
  schoolFinishedHandle: function(e) {
    console.log(e.detail.content)
    if (e.detail.action == 1) {
      app.userSetting.university = e.detail.content
      //继续下一题

    }else if(e.detail.action == 2){
      //继续下一题
    }else{
      //返回上一题
    }
  },
  majorFinishedHandle: function(e) {
    console.log(e.detail.content)
    if (e.detail.action == 1) {
      app.userSetting.major = e.detail.content
      //继续下一题

    } else if (e.detail.action == 2) {
      //继续下一题
    } else {
      //返回上一题
    }
  },
  wxFinishedHandle: function (e) {
    console.log(e.detail.content)
    if (e.detail.action == 1) {
      if (!util.wxFormatCheck(e.detail.content)) {
        wx.showToast({
          title: '请填写正确的微信号',
          icon: 'none'
        })
        return
      }
      app.userSetting.wx = e.detail.content
      //继续下一题
    } else if (e.detail.action == 2) {
      app.userSetting.wx = ''
      //继续下一题
    }else{
      //返回上一题

    }
  },
  uploadFinishedHandle: function(e) {
    if (e.detail.action == 1) {
      console.log('个人照片上传步骤完成')
      //继续下一步
    } else if (e.detail.action == 2){
      //继续下一步
    } else{
      //返回上一题
    }
  },
  customTagDidClick: function() {
    wx.navigateTo({
      url: '../infoTagCustom/infoTagCustom',
    })
  },
  tagSelectedFinishedHandle: function(e) {
    if (e.detail.action == 0){
      //返回上一题
    }else{
      console.log(e.detail)
      app.userSetting.tagSelectedArray = e.detail.tagSelectedArray
      app.userSetting.customTagSelectedArray = e.detail.customTagSelectedArray
    }
  },
  addTag: (tag) => {
    console.log(tag)
    _this.setData({
      cutsomTag: tag
    })
  },
    maleDidSelected :function() {
      this.setData({
        manSelected:'btnSelected',
        womenSelected: 'btnNormal',
        sex: 1
      })
      _this.handleUpdate()
      // getCurrentPages.pop()
      wx.navigateTo({
        url: '../infoBirdthday/infoBirdthday',
      })
    },
    ladyDidSelected: function () {
      this.setData({
        manSelected: 'btnNormal',
        womenSelected: 'btnSelected',
        sex: 2
      })
      _this.handleUpdate()
      // getCurrentPages.pop()
      wx.navigateTo({
        url: '../infoBirdthday/infoBirdthday',
      })
    },
    onLoad :function() {
      _this = this

      //这是共享图片组件调起生成图片动作的代码
      _this.setData({
        fillContent: shareText,
        action: 'create'
      })
    },
    onShareAppMessage(res) {
      if (res.from === 'button') {
        // 来自页面内转发按钮
      }
      
      return {
        title: '虫洞小程序',
        path: '/pages/index/index?id=123',
        imageUrl: _this.data.imagePath
      }
    },

    handleUpdate: () => {
      var data = { 'sex': _this.data.sex }
      util.updateUserInfo(_this.requestDidResponse, _this.requestDidFaild, data)
    },
    requestDidResponse: (res) => {
      console.log('did receive response: ' + res)
      if (res.status == '200') {
        console.log('sex set success')
      }
    },
    requestDidFaild: (res) => {

    },

    //以下是生成、保存分享图片的回调
    saveSuccess: () => {
      console.log('图片保存成功')

    },
    saveFailed: () => {
      console.log('图片保存失败')
    },
    createSuccess: (e) => {
      console.log('图片生成成功')
      _this.data.imagePath = e.detail.imageFilePath
      //这是共享图片组件调起保存动作的代码
      _this.setData({
        action: 'save'
      })
    },
    createFailed: () => {
      console.log('图片生成失败')
    }
})